﻿@model HanGu.Entity.Manager
@{
    ViewBag.Title = "用户(添加/修改)";
    //Layout = "~/Views/Shared/AdminLayout.cshtml";
    var Roles = ViewData["Roles"] as SelectList;
    var Parents = ViewData["Parents"] as List<HanGu.Entity.Manager>;
    var UserStatus = ViewData["UserStatus"] as SelectList;
    var Sexs = ViewData["Sexs"] as SelectList;

    var CurentUser = Session["CurentUser"] as HanGu.Entity.CurrentUserDTO;
    var SelectedParents = new List<string>();
    if (Model.Parents != null)
    {
        SelectedParents = Model.Parents.Select(c => c.ID.ToString()).ToList();
    }
}
<script>
    $(function () {
        $("#UserForm").validate({
            rules: {
                User: {
                    remote: { //验证用户名是否存在
                        type: "POST",
                        url: "Users/Default/UserExitsed", //servlet
                        data: {
                            User: function () { return $("#User").val(); }
                        }
                    }
                }

            },
            messages: {
                User: { remote: jQuery.format("用户名已经被注册") }
            }
        });
    });


    $(document).ready(function () {
        $("#Sex").val('@(!Model.Sex.HasValue ? 2 : Model.Sex)');
    });   
</script>
<div class="pageContent">
    <form method="post" id="UserForm" action="Users/Default/create?OpID=@ViewData["OperateID"]" class="pageForm required-validate"
    onsubmit="return validateCallback(this, navTabAjaxDone);">
    @Html.ValidationSummary(true)
     @if (Model.ID > 0){
     @Html.HiddenFor(model => model.User)}
    <div class="pageFormContent" layouth="110">
        @Html.HiddenFor(model => model.ID)
        <p>
            <label>
                用户名：</label>
            @if (Model.ID > 0)
            { 
                @Model.User               
            }
            else
            {
                @Html.TextBoxFor(model => model.User, new { @class = "UserExitsed required number" })
            }
            @Html.ValidationMessageFor(model => model.User)
        </p>
        @if (Model.ID < 1)
        {            
            
            <p>
                <label>
                    密码：</label>
                @Html.PasswordFor(model => model.Pwd, new { @class = "required alphanumeric", @Type = "password", minlength = "6", maxlength = "20", alt = "字母、数字、下划线 6-20位" })
                @Html.ValidationMessageFor(model => model.Pwd)
            </p>

            <p>
                <label>
                    确认密码：</label>
                @Html.PasswordFor(model => model.Pwd, new { @class = "required", @Type = "password", equalto = "#Pwd" })
                @Html.ValidationMessageFor(model => model.Pwd)
            </p>
        }
        else
        { 
            @Html.HiddenFor(model => model.Pwd)
        }
        <p>
            <label>
                姓名：</label>
            @Html.EditorFor(model => model.RealName, new { @class = "required" })
            @Html.ValidationMessageFor(model => model.RealName)
        </p>
        <p>
            <label>
                角色：</label>
            @Html.DropDownListFor(model => model.RoleID, Roles, HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "required" })
            @Html.ValidationMessageFor(model => model.RoleID)
        </p>
        <p>
            <label>
                职位：</label>
            @Html.EditorFor(model => model.Position)
            @Html.ValidationMessageFor(model => model.Position)
        </p>
        @* <p>
            <label>
                是否直属：</label>
            @Html.CheckBox("IsDirectly", Model.IsDirectly)
            @Html.ValidationMessageFor(model => model.IsDirectly)
        </p>*@
        @if (Model.ID > 0 && CurentUser.Roles.Where(c => c.ID == "Users_4").FirstOrDefault() != null)
        {
            <p>
                <label>
                    用户状态：</label>
                @Html.DropDownListFor(model => model.Status, UserStatus, HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "required" })
                @Html.ValidationMessageFor(model => model.Status)
            </p>
        }
        <p>
            <label>
                入职时间：</label>
            @Html.TextBoxFor(model => model.InWorkDate, new { @class = "date", format = "yyyy-MM-dd", @readonly = "true" })
            @Html.ValidationMessageFor(model => model.InWorkDate)
        </p>
        @if (Model.ID > 0)
        {
            <p>
                <label>
                    离职时间：</label>
                @Html.TextBoxFor(model => model.OutWorkDate, new { @class = "date", format = "yyyy-MM-dd", @readonly = "true" })
                @Html.ValidationMessageFor(model => model.OutWorkDate)
            </p>
        }
        <p>
            <label>
                年龄：</label>
            @Html.TextBoxFor(model => model.Age, new { @class = "number" })
            @Html.ValidationMessageFor(model => model.Age)
        </p>
        <p>
            <label>
                性别：</label>
            @Html.DropDownListFor(model => model.Sex, Sexs, HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "required" })
            @Html.ValidationMessageFor(model => model.Sex)
        </p>
        <p>
            <label>
                创建时间：</label>
            @Html.DisplayFor(model => model.CreateTime)
            @Html.ValidationMessageFor(model => model.CreateTime)
        </p>
        <p>
            <label>
                创建人：</label>
            @Html.DisplayFor(model => model.Creator)
            @Html.ValidationMessageFor(model => model.InWorkDate)
        </p>
        <div class="divider">
        </div>
        <p style="width: 100%; height: auto;">
            <label>
                所属上级：</label>
            @foreach (var item in Parents.Where(c => c.ID != Model.ID))
            {
                <input name="Parents" class="checkbox" id="Parents" style="magin-left: 5px;" type="checkbox" CHECKED="@SelectedParents.Contains((item.ID.ToString()))" value="@item.ID"/>                
                @item.RealName
                @item.User
            }
        </p>
    </div>
    <div class="formBar">
        <ul>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit">
                            提交</button></div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">
                            取消</button></div>
                </div>
            </li>
        </ul>
    </div>
    </form>
</div>
